#encoding:utf-8
#{'code': 0, 'success': True, 'msg': '0', 'data': [{'ip': '122.242.62.57', 'port': 4256, 'expire_time': ''2019-07-11 16:35:47}]}

from datetime import datetime,timedelta
#timedelta 两个datetime之间的时间差
class ProxyModel(object):
    def __init__(self,data):
        self.ip = data['ip']
        self.port = data['port']
        self.expire_str = data['expire_time']
        #2019-07-11 16:35:47
        date_str,time_str = self.expire_str.split(" ")
        year,month,day = date_str.split("-")
        hour,minute,seconds = time_str.split(":")
        self.expire_time = datetime(year=int(year),month=int(month),day=int(day),hour=int(hour),minute=int(minute),second=int(seconds))
        #https://ip:port
        self.proxy = "https://{}:{}".format(self.ip,self.port)
        self.blacked = False

    @property #可以把方法当作特殊属性来对待
    def is_expiring(self):
        # datetime.strptime()
        now = datetime.now()
        if(self.expire_time-now) < timedelta(seconds=5):
            #timedelta表示即将结束之前 5秒
            return True
        else:
            return False

